package com.yanqu.road.server.cmd.systemgroup.newmonopolymkt;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.CrossAppointCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.systemgroup.newmonopolymkt.CrossNewMonopolyMarketGroup;
import com.yanqu.road.server.manager.systemgroup.newmonopolymkt.CrossNewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;


@Cmd(code = Protocol.C_CROSS_NEW_MONOPOLY_MARKET_GET_NOTICE, desc = "查看榷场公告")
public class CrossNewMonopolyMarketGetNoticeCmd extends CrossAppointCommand {

    private long userId;
    private int type;
    private int page;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        NewMonopolyMarketProto.NewMonopolyMarketGetNoticeReqMsg req = NewMonopolyMarketProto.NewMonopolyMarketGetNoticeReqMsg.parseFrom(packet.getBytes());
        type = req.getType();
        page = req.getPage();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        CrossNewMonopolyMarketGroup monopolyMarket = CrossNewMonopolyMarketMgr.getMarket(groupId);
        if(monopolyMarket != null){
            MessageHelper.sendPacket(serverId, packet.getPlayerId() , YanQuMessageUtils.buildMessage(Protocol.U_NEW_MONOPOLY_MARKET_GET_NOTICE,
                    monopolyMarket.getNotice(type,page,serverId)));
        }else {
            //todo
        }
    }

    @Override
    public void sendData() {

    }
}
